package com.fwtai.api;

import com.fwtai.bean.PageFormData;
import com.fwtai.datasource.DaoHandle;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * 门店管理访问数据库
 * @作者 田应平
 * @版本 v1.0
 * @创建时间 2023-04-04 17:45:50
 * @QQ号码 444141300
 * @Email service@yinlz.com
 * @官网 <url>http://www.fwtai.com</url>
*/
@Repository
public class ApiGoodsDao{

  private final DaoHandle dao;

  public ApiGoodsDao(final DaoHandle dao){
    this.dao = dao;
  }

  public HashMap<String,Object> queryGoodsType1(final long kid){
    return dao.queryForHashMap("api_goods.queryGoodsType1",kid);
  }

  public HashMap<String,Object> queryGoodsType2(final long kid){
    return dao.queryForHashMap("api_goods.queryGoodsType2",kid);
  }

  public HashMap<String,Object> queryGoodsType3(final long kid){
    return dao.queryForHashMap("api_goods.queryGoodsType3",kid);
  }

  public List<HashMap<String,Object>> getListData(final PageFormData formData){
    return dao.queryForListHashMap("api_goods.listData",formData);
  }

  public Integer getListTotal(final PageFormData formData){
    return dao.queryForInteger("api_goods.listTotal",formData);
  }

  //获取获取区级[合伙人]的商品列表
  public List<HashMap<String,Object>> listPagePartner(final PageFormData formData){
    return dao.queryForListHashMap("api_goods.listPagePartner",formData);
  }

  public List<HashMap<String,Object>> listInventoryProxy(final PageFormData formData){
    return dao.queryForListHashMap("api_goods.listInventoryProxy",formData);
  }

  public List<HashMap<String,Object>> listInventoryStore(final PageFormData formData){
    return dao.queryForListHashMap("api_goods.listInventoryStore",formData);
  }

  public List<HashMap<String,Object>> listCouponStore(final PageFormData formData){
    return dao.queryForListHashMap("api_goods.listCouponStore",formData);
  }

  public List<HashMap<String,Object>> listCouponProxy(final PageFormData formData){
    return dao.queryForListHashMap("api_goods.listCouponProxy",formData);
  }

  @Transactional
  public int addPriorityProxy(final long kid,final HashMap<String,Long> params){
    final int rows1 = dao.execute("api_goods.editBatchProxy",params);
    final int rows2 = dao.execute("api_goods.editProxyPriority",kid);
    return rows1 > 0 && rows2 > 0 ? rows2 : 0;
  }

  @Transactional
  public int addPriorityStore(final long kid,final HashMap<String,Long> params){
    final int rows1 = dao.execute("api_goods.editBatchStore",params);
    final int rows2 = dao.execute("api_goods.editStorePriority",kid);
    return rows1 > 0 && rows2 > 0 ? rows2 : 0;
  }

  public Long getStoreUser(final long loginId){
    return dao.queryForLong("api_goods.getStoreUser",loginId);
  }

  public HashMap<String,Object> getGoods(final String code){
    return dao.queryForHashMap("api_goods.getGoods",code);
  }
}